home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume8 / graph+ / part03 < prev    next >
Encoding:
Internet Message Format  |  1987-03-01  |  49.0 KB

  1. Path: mirror!adelie!necntc!husc6!seismo!munnari!sources-request
  2. From: sources-request@munnari.oz
  3. Newsgroups: mod.sources
  4. Subject: v08i083:  Graph+, A Graph Plotting Program, Part03/03
  5. Message-ID: <1433@munnari.oz>
  6. Date: 28 Feb 87 07:38:51 GMT
  7. Sender: kre@munnari.oz
  8. Lines: 2287
  9. Approved: kre@munnari.oz.au
  10.  
  11. Submitted by: Alan Kent <ajk@goanna.oz.au>
  12. Mod.sources: Volume 8, Issue 83
  13. Archive-name: graph+/Part03
  14.  
  15. #! /bin/sh
  16. # This is a shell archive, meaning:
  17. # 1.  Remove everything above the #! /bin/sh line.
  18. # 2.  Save the resulting test in a file
  19. # 3.  Execute the file with /bin/sh (not csh) to create the files:
  20. #
  21. #        generate.c
  22. #        global.c
  23. #        group.c
  24. #        include.c
  25. #        join.c
  26. #        main.c
  27. #        max.c
  28. #        min.c
  29. #        new.c
  30. #        newtable.c
  31. #        numcols.c
  32. #        parmnode.c
  33. #        printtab.c
  34. #        project.c
  35. #        readtab.c
  36. #        reset.c
  37. #        saveload.c
  38. #        select.c
  39. #        sort.c
  40. #        sum.c
  41. #        tabdeclr.c
  42. #        tabnode.c
  43. #        vardeclr.c
  44. #        lex.l
  45. #
  46. # Created by ajk on Wed Feb 25 09:25:38 EST 1987
  47. #
  48. if test -f 'generate.c'
  49. then
  50.     echo shar: will not over-write existing file "'generate.c'"
  51. else
  52. echo extracting "'generate.c'"
  53. sed 's/^X//' >generate.c <<'SHAR_EOF'
  54. X/*
  55. X * Copyright (C) 1986   Alan Kent
  56. X *
  57. X * Permission is granted to freely distribute part or
  58. X * all of this code as long as it is not for profit
  59. X * and this message is retained in the code.
  60. X *
  61. X * No resposibility is taken for any damage or incorect
  62. X * results this program generates.
  63. X * 
  64. X */
  65. X
  66. X
  67. X#include <stdio.h>
  68. X#include "graph.h"
  69. X
  70. X
  71. X
  72. Xextern table_st *new_table ();
  73. X
  74. X
  75. X
  76. Xtable_st *
  77. Xgenerate ( range , interval )
  78. Xrange_st *range;
  79. Xint_st *interval;
  80. X{
  81. X    table_st *table;
  82. X    int num_int;
  83. X    int i;
  84. X    double value;
  85. X
  86. X    if ( interval == NULL )
  87. X    abort ( "GENERATE with no interval specified" );
  88. X    if ( range == NULL )
  89. X    abort ( "GENERATE with no range specified" );
  90. X
  91. X    if ( interval->int_type == INUMINT )
  92. X    num_int = interval->value;
  93. X    else
  94. X    num_int = ( range->max - range->min ) / interval->value + 1;
  95. X    table = new_table ( 1 , num_int );
  96. X
  97. X    if ( interval->int_type == INUMINT ) {
  98. X    value = range->min;
  99. X    for ( i = 0; i < num_int; i++ )
  100. X        table->data[i] = range->min
  101. X        + ( range->max - range->min ) * (double)i / interval->value;
  102. X    }
  103. X    else {
  104. X    value = range->min;
  105. X    for ( i = 0; i < num_int; i++ ) {
  106. X        table->data[i] = value;
  107. X        value += interval->value;
  108. X    }
  109. X    }
  110. X    return ( table );
  111. X}
  112. SHAR_EOF
  113. if test 1206 -ne "`wc -c < 'generate.c'`"
  114. then
  115.     echo shar: error transmitting "'generate.c'" '(should have been 1206 characters)'
  116. fi
  117. fi
  118. if test -f 'global.c'
  119. then
  120.     echo shar: will not over-write existing file "'global.c'"
  121. else
  122. echo extracting "'global.c'"
  123. sed 's/^X//' >global.c <<'SHAR_EOF'
  124. X/*
  125. X * Copyright (C) 1986   Alan Kent
  126. X *
  127. X * Permission is granted to freely distribute part or
  128. X * all of this code as long as it is not for profit
  129. X * and this message is retained in the code.
  130. X *
  131. X * No resposibility is taken for any damage or incorect
  132. X * results this program generates.
  133. X * 
  134. X */
  135. X
  136. X
  137. X#include <stdio.h>
  138. X#include "graph.h"
  139. X
  140. Xint linenum = 1;
  141. Xchar *infilename;
  142. Xchar *PROG_NAME = "graph+";
  143. Xaxis_st xaxis , yaxis;
  144. Xgraph_st graph[ MAX_GRAPHS ];
  145. Xint num_graphs = 0;
  146. Xchar *graph_label = NULL;
  147. Xint warnings;
  148. Xint gargc;
  149. Xchar **gargv;
  150. Xint horiz_legend;    /* LEFT, CENTER, RIGHT */
  151. Xint vert_legend;    /* TOP, MIDDLE, BOTTOM */
  152. X
  153. SHAR_EOF
  154. if test 623 -ne "`wc -c < 'global.c'`"
  155. then
  156.     echo shar: error transmitting "'global.c'" '(should have been 623 characters)'
  157. fi
  158. fi
  159. if test -f 'group.c'
  160. then
  161.     echo shar: will not over-write existing file "'group.c'"
  162. else
  163. echo extracting "'group.c'"
  164. sed 's/^X//' >group.c <<'SHAR_EOF'
  165. X/*
  166. X * Copyright (C) 1986   Alan Kent
  167. X *
  168. X * Permission is granted to freely distribute part or
  169. X * all of this code as long as it is not for profit
  170. X * and this message is retained in the code.
  171. X *
  172. X * No resposibility is taken for any damage or incorect
  173. X * results this program generates.
  174. X * 
  175. X */
  176. X
  177. X
  178. X#include <stdio.h>
  179. X#include "graph.h"
  180. X#include "y.tab.h"
  181. X
  182. X
  183. X/*#define DEBUG(parms)    fprintf parms*/
  184. X#define DEBUG(parms)
  185. X
  186. X
  187. X/* This produces a 3 column table: $1 = lower bound of range, $2 = upper */
  188. X/* bound of range, $3 = result for range */
  189. X
  190. X
  191. Xextern table_st *new_table ();
  192. Xextern double ceil ();
  193. Xextern tnode_st *tab_node ();
  194. Xextern double call_var_fun ();
  195. Xextern double min_fun ();
  196. Xextern double max_fun ();
  197. X
  198. X
  199. X
  200. Xtable_st *
  201. Xgroup ( table , range , interval , fun_name )
  202. Xtable_st *table;    /* table of data to group */
  203. Xrange_st *range;    /* contains min,max and interval sizes */
  204. Xint_st *interval;
  205. Xchar *fun_name;        /* expression to evaluate per interval */
  206. X{
  207. X    double low , high;
  208. X    double value;
  209. X    int i , intv , num_intervals , new_index;
  210. X    table_st *newtab;
  211. X    table_st *temptab;
  212. X    int intv_from , intv_to;
  213. X    range_st st_range;
  214. X    parm_st parm;
  215. X
  216. X
  217. X    if ( interval == NULL )
  218. X    abort ( "code error for group(): NULL interval pointer" );
  219. X    if ( num_cols ( table ) != 2 )
  220. X    abort ( "GROUP requires two column tables" );
  221. X
  222. X    if ( range == NULL ) {
  223. X    range = &st_range;
  224. X    st_range.min = min_fun ( table , 0 , table->size );
  225. X    st_range.max = max_fun ( table , 0 , table->size );
  226. X    }
  227. X
  228. X    if ( interval->int_type == INUMINT ) {
  229. X    num_intervals = (int) ceil ( interval->value );
  230. X    }
  231. X    else {
  232. X    num_intervals = 0;
  233. X    for ( low = range->min; low <= range->max; low += interval->value )
  234. X        num_intervals++;
  235. X    }
  236. X    newtab = new_table ( 3 , num_intervals );
  237. X
  238. XDEBUG((stderr,"min %f, max %f, num_int %d\n",range->min,range->max,num_intervals));
  239. X
  240. X    /* now scan through each interval and determine range from table */
  241. X    /* that lie within that interval */
  242. X
  243. X    intv_to = 0;
  244. X    while ( intv_to < table->size  &&  table->data[intv_to] < range->min )
  245. X    intv_to++;
  246. X    intv_to--;
  247. X    intv = 0;
  248. X    new_index = 0;
  249. X    low = range->min;
  250. X    high = range->min;
  251. X    while ( intv < num_intervals ) {
  252. X    if ( interval->int_type == INUMINT )
  253. X        high = range->min + ( ((double)intv + 1)
  254. X        * ( range->max - range->min ) / (double)num_intervals );
  255. X    else
  256. X        high += interval->value;
  257. XDEBUG((stderr,"intv %d of %d, low = %f, high = %f\n",intv,num_intervals,low,high));
  258. X    for ( i = intv_to + 1; i < table->size; i++ ) {
  259. X        value = table->data[i];
  260. X        if ( value < low )
  261. X        abort ( "table must be sorted on group (first) field for GROUP" );
  262. X        /* on last interval, include upper bound */
  263. X        if ( intv + 1 == num_intervals ) {
  264. X        if ( value > high )
  265. X            break;
  266. X        }
  267. X        else {
  268. X        if ( value >= high )
  269. X            break;
  270. X        }
  271. X    }
  272. X    intv_from = intv_to + 1;
  273. X    intv_to = i - 1;
  274. X
  275. X    /* only do something if the interval contains data */
  276. X
  277. X    if ( intv_to > intv_from ) {
  278. X
  279. XDEBUG((stderr,"intv_to %d > intv_from %d\n",intv_to,intv_from));
  280. X
  281. X        if ( interval->int_type == INUMINT )
  282. X        value = range->min + ( ((double)(intv+1))
  283. X            * ( range->max - range->min ) / (double)num_intervals );
  284. X        else
  285. X        value = ((double)(intv+1)) * interval->value;
  286. X        newtab->next->data[ new_index ] = value;
  287. X
  288. X        if ( interval->int_type == INUMINT )
  289. X        value = range->min + ( ((double)intv)
  290. X            * ( range->max - range->min ) / (double)num_intervals );
  291. X        else
  292. X        value = ((double)intv) * interval->value;
  293. X        newtab->data[ new_index ] = value;
  294. X
  295. X        temptab = new_table ( 1 , intv_to - intv_from + 1 );
  296. X        for ( i = 0; i < temptab->size; i++ )
  297. X        temptab->data[i] = table->next->data[ i + intv_from ];
  298. X        parm.next = NULL;
  299. X        parm.parm_type = TABLE;
  300. X        parm.tab_expr = tab_node ( TAB_CONST );
  301. X        parm.tab_expr->table = temptab;
  302. X        value = call_var_fun ( fun_name , &parm , NULL , 0 );
  303. X        free_table ( temptab );
  304. XDEBUG((stderr,"Function returns %f\n",value));
  305. X
  306. X        newtab->next->next->data[ new_index ] = value;
  307. X
  308. X        new_index++;
  309. X    }
  310. Xelse
  311. XDEBUG((stderr,"intv_from %d <= intv_to %d\n",intv_from,intv_to));
  312. X    intv++;
  313. X    low = high;
  314. X    }
  315. X    newtab->size = new_index;
  316. X    free_table ( table );
  317. X    return ( newtab );
  318. X}
  319. SHAR_EOF
  320. if test 4186 -ne "`wc -c < 'group.c'`"
  321. then
  322.     echo shar: error transmitting "'group.c'" '(should have been 4186 characters)'
  323. fi
  324. fi
  325. if test -f 'include.c'
  326. then
  327.     echo shar: will not over-write existing file "'include.c'"
  328. else
  329. echo extracting "'include.c'"
  330. sed 's/^X//' >include.c <<'SHAR_EOF'
  331. X/*
  332. X * Copyright (C) 1986   Alan Kent
  333. X *
  334. X * Permission is granted to freely distribute part or
  335. X * all of this code as long as it is not for profit
  336. X * and this message is retained in the code.
  337. X *
  338. X * No resposibility is taken for any damage or incorect
  339. X * results this program generates.
  340. X * 
  341. X */
  342. X
  343. X
  344. X#include <stdio.h>
  345. X
  346. X
  347. X/* This is possibly a bit dangerous as i am not sure how yacc will take */
  348. X/* to being called recursively */
  349. X
  350. X
  351. Xextern FILE *yyin;
  352. Xextern int linenum;
  353. Xextern char *infilename;
  354. X
  355. X
  356. Xinclude ( filename )
  357. Xchar *filename;
  358. X{
  359. X    FILE *old_fp , *fp;
  360. X    int old_linenum;
  361. X    char *old_filename;
  362. X
  363. X    if ( filename == NULL )
  364. X    return;
  365. X    if ( ( fp = fopen ( filename , "r" ) ) == NULL )
  366. X    abort ( "failed to open include file '%s'" , filename );
  367. X    old_fp = yyin;
  368. X    old_filename = infilename;
  369. X    old_linenum = linenum;
  370. X    yyin = fp;
  371. X    infilename = filename;
  372. X    linenum = 1;
  373. X    yyparse ();
  374. X    fclose ( yyin );
  375. X    yyin = old_fp;
  376. X    infilename = old_filename;
  377. X    linenum = old_linenum;
  378. X    yyparse ();
  379. X}
  380. X
  381. SHAR_EOF
  382. if test 1019 -ne "`wc -c < 'include.c'`"
  383. then
  384.     echo shar: error transmitting "'include.c'" '(should have been 1019 characters)'
  385. fi
  386. fi
  387. if test -f 'join.c'
  388. then
  389.     echo shar: will not over-write existing file "'join.c'"
  390. else
  391. echo extracting "'join.c'"
  392. sed 's/^X//' >join.c <<'SHAR_EOF'
  393. X/*
  394. X * Copyright (C) 1986   Alan Kent
  395. X *
  396. X * Permission is granted to freely distribute part or
  397. X * all of this code as long as it is not for profit
  398. X * and this message is retained in the code.
  399. X *
  400. X * No resposibility is taken for any damage or incorect
  401. X * results this program generates.
  402. X * 
  403. X */
  404. X
  405. X
  406. X#include <stdio.h>
  407. X#include "graph.h"
  408. X
  409. X
  410. Xextern char *new ();
  411. Xextern table_st *new_table ();
  412. X
  413. X
  414. Xtable_st *
  415. Xjoin ( tab1 , tab2 , attr1 , attr2 )
  416. Xtable_st *tab1 , *tab2;
  417. Xint attr1 , attr2;
  418. X{
  419. X    double floor ();
  420. X
  421. X    int i , j , j0 , newsize , ni;
  422. X    int free1 , free2;
  423. X    double *data1 , *data2;
  424. X    table_st *newtab , *pcol , *pcol1 , *pcol2;
  425. X
  426. X
  427. X    if ( attr1 == 0 ) {
  428. X    
  429. X    /* to make life easy, create a dummy array for $0 */
  430. X
  431. X    data1 = (double *) new ( sizeof ( double ) * tab1->size );
  432. X    for ( i = 0; i < tab1->size; i++ )
  433. X        data1[i] = i + 1;
  434. X    free1 = 1;
  435. X    }
  436. X    else {
  437. X    
  438. X    /* look for column in table */
  439. X
  440. X    for ( i = 1, pcol1 = tab1; pcol1 != NULL  &&  i != attr1; pcol1 = pcol1->next, i++ );
  441. X    if ( pcol1 == NULL )
  442. X        abort ( "Illegal attribute selected for join" );
  443. X    data1 = pcol1->data;
  444. X    free1 = 0;
  445. X    }
  446. X
  447. X    if ( attr2 == 0 ) {
  448. X    
  449. X    /* to make life easy, create a dummy array for $0 */
  450. X
  451. X    data2 = (double *) new ( sizeof ( double ) * tab2->size );
  452. X    for ( i = 0; i < tab2->size; i++ )
  453. X        data2[i] = i + 1;
  454. X    free2 = 1;
  455. X    }
  456. X    else {
  457. X    
  458. X    /* look for column in table */
  459. X
  460. X    for ( i = 1, pcol2 = tab2; pcol2 != NULL  &&  i != attr2; pcol2 = pcol2->next, i++ );
  461. X    if ( pcol2 == NULL )
  462. X        abort ( "Illegal attribute selected for join" );
  463. X    data2 = pcol2->data;
  464. X    free2 = 0;
  465. X    }
  466. X
  467. X    /* check that data has been sorted on join field, and if not, sort it */
  468. X
  469. X    for ( i = 0; i < tab1->size - 1; i++ ) {
  470. X    if ( data1[i] > data1[i+1] ) {
  471. X        sort ( tab1 , attr1 );
  472. X        break;
  473. X    }
  474. X    }
  475. X    for ( i = 0; i < tab2->size - 1; i++ ) {
  476. X    if ( data2[i] > data2[i+1] ) {
  477. X        sort ( tab2 , attr2 );
  478. X        break;
  479. X    }
  480. X    }
  481. X
  482. X    /* determine how big the final table will be */
  483. X
  484. X    i = 0;
  485. X    j0 = 0;
  486. X    newsize = 0;
  487. X    for ( i = 0; i < tab1->size; i++ ) {
  488. X    while ( j0 < tab2->size  &&  data1[i] > data2[j0] )
  489. X        j0++;
  490. X    for ( j = j0; j < tab2->size  &&  data1[i] == data2[j]; j++ ) {
  491. X        newsize++;
  492. X    }
  493. X    }
  494. X
  495. X    /* ok, build the new table */
  496. X
  497. X    newtab = new_table ( num_cols ( tab1 ) + num_cols ( tab2 ) , newsize );
  498. X
  499. X    /* now do the join */
  500. X
  501. X    i = 0;
  502. X    j0 = 0;
  503. X    ni = 0;
  504. X    for ( i = 0; i < tab1->size; i++ ) {
  505. X    while ( j0 < tab2->size  &&  data1[i] > data2[j0] ) {
  506. X        j0++;
  507. X    }
  508. X    for ( j = j0; j < tab2->size  &&  data1[i] == data2[j]; j++ ) {
  509. X        pcol = newtab;
  510. X        for ( pcol1 = tab1; pcol1 != NULL; pcol1 = pcol1->next ) {
  511. X        pcol->data[ni] = pcol1->data[i];
  512. X        pcol = pcol->next;
  513. X        }
  514. X        for ( pcol2 = tab2; pcol2 != NULL; pcol2 = pcol2->next ) {
  515. X        pcol->data[ni] = pcol2->data[j];
  516. X        pcol = pcol->next;
  517. X        }
  518. X        ni++;
  519. X    }
  520. X    }
  521. X    if ( ni != newsize )
  522. X    abort ( "Internal error in JOIN - pass 2 returns different size than pass 1" );
  523. X
  524. X    /* free up and return */
  525. X
  526. X    free_table ( tab1 );
  527. X    free_table ( tab2 );
  528. X    if ( free1 )
  529. X    release ( data1 );
  530. X    if ( free2 )
  531. X    release ( data2 );
  532. X    return ( newtab );
  533. X}
  534. X
  535. SHAR_EOF
  536. if test 3126 -ne "`wc -c < 'join.c'`"
  537. then
  538.     echo shar: error transmitting "'join.c'" '(should have been 3126 characters)'
  539. fi
  540. fi
  541. if test -f 'main.c'
  542. then
  543.     echo shar: will not over-write existing file "'main.c'"
  544. else
  545. echo extracting "'main.c'"
  546. sed 's/^X//' >main.c <<'SHAR_EOF'
  547. X/*
  548. X * Copyright (C) 1986   Alan Kent
  549. X *
  550. X * Permission is granted to freely distribute part or
  551. X * all of this code as long as it is not for profit
  552. X * and this message is retained in the code.
  553. X *
  554. X * No resposibility is taken for any damage or incorect
  555. X * results this program generates.
  556. X * 
  557. X */
  558. X
  559. X
  560. X#include <stdio.h>
  561. X#include <signal.h>
  562. X#include "graph.h"
  563. X#include "y.tab.h"
  564. X
  565. X/* if not on cc line, use default */
  566. X#ifndef GLOB_LIB
  567. X#define GLOB_LIB "/usr/lib/graph+rc"
  568. X#endif
  569. X
  570. X
  571. Xextern char *getenv ();
  572. X
  573. X
  574. Xextern char *PROG_NAME;
  575. Xextern int gargc;
  576. Xextern char **gargv;
  577. Xextern char *infilename;
  578. Xextern int linenum;
  579. Xextern axis_st xaxis;
  580. Xextern axis_st yaxis;
  581. Xextern int warnings;
  582. Xextern FILE *yyin;
  583. Xextern int horiz_legend;
  584. Xextern int vert_legend;
  585. Xextern int num_graphs;
  586. X
  587. X
  588. Xmain ( argc , argv )
  589. Xint argc;
  590. Xchar **argv;
  591. X{
  592. X    int float_exception ();
  593. X
  594. X    char *home;
  595. X    char buf[200];
  596. X    FILE *fp;
  597. X    int read_stdin;
  598. X
  599. X
  600. X    signal ( SIGFPE , float_exception );
  601. X    if ( argc < 1 ) {
  602. X    fprintf ( stderr , "usage: %s [ commandfile | - ] [ parameter ... ]\n" , PROG_NAME );
  603. X    exit ( 1 );
  604. X    }
  605. X
  606. X    warnings = 1;    /* should be an option */
  607. X
  608. X    num_graphs = 0;
  609. X    horiz_legend = RIGHT;
  610. X    vert_legend = TOP;
  611. X
  612. X    xaxis.format = yaxis.format = "%.1f";
  613. X    xaxis.user_format = yaxis.user_format = NULL;
  614. X    xaxis.label = yaxis.label = "";
  615. X    xaxis.scale = yaxis.scale = AUTO;
  616. X    xaxis.frame = yaxis.frame = GRID;
  617. X    xaxis.linear = yaxis.linear = LINEAR;
  618. X    xaxis.auto_tick_size = yaxis.auto_tick_size = 1;
  619. X    xaxis.range.min = yaxis.range.min = 0.0;
  620. X    xaxis.range.max = yaxis.range.max = -1.0;
  621. X    xaxis.interval = yaxis.interval = NULL;
  622. X
  623. X    pdef_fun ();
  624. X    pdef_var ();
  625. X    pdef_tab ();
  626. X
  627. X    if ( ( fp = fopen ( GLOB_LIB , "r" ) ) != NULL ) {
  628. X    yyin = fp;
  629. X    linenum = 1;
  630. X    infilename = GLOB_LIB;
  631. X    yyparse ();
  632. X    fclose ( yyin );
  633. X    }
  634. X
  635. X    if ( ( home = getenv ( "HOME" ) ) != NULL ) {
  636. X    sprintf ( buf , "%s/.graph+rc" , home );
  637. X    if ( ( fp = fopen ( buf , "r" ) ) != NULL ) {
  638. X        yyin = fp;
  639. X        linenum = 1;
  640. X        infilename = buf;
  641. X        yyparse ();
  642. X        fclose ( yyin );
  643. X    }
  644. X    }
  645. X
  646. X    read_stdin = ( argc < 2  ||  strcmp ( argv[1] , "-" ) == 0 );
  647. X
  648. X    gargc = argc;
  649. X    gargv = argv;
  650. X
  651. X    if ( ! read_stdin ) {
  652. X    if ( ( fp = fopen ( argv[1] , "r" ) ) == NULL ) {
  653. X        fprintf ( stderr , "%s: failed to open command file '%s'\n" ,
  654. X        PROG_NAME , argv[1] );
  655. X        exit ( 1 );
  656. X    }
  657. X    yyin = fp;
  658. X    infilename = argv[1];
  659. X    linenum = 1;
  660. X    }
  661. X    else {
  662. X    yyin = stdin;
  663. X    infilename = "stdin";
  664. X    linenum = 1;
  665. X    }
  666. X
  667. X    yyparse ();
  668. X
  669. X}
  670. X
  671. X
  672. X/* FOR VAX-11 ONLY - well, our vax anyway */
  673. X
  674. Xfloat_exception ( sig , code )
  675. Xint sig , code;
  676. X{
  677. X    switch ( code ) {
  678. X
  679. X#ifdef FPE_INTOVF_TRAP 
  680. X    case FPE_INTOVF_TRAP : abort ( "Integer overflow trap" );
  681. X#endif
  682. X#ifdef FPE_INTDIV_TRAP 
  683. X    case FPE_INTDIV_TRAP : abort ( "Integer division by zero trap" );
  684. X#endif
  685. X#ifdef FPE_FLTOVF_TRAP 
  686. X    case FPE_FLTOVF_TRAP : abort ( "Floating point overflow trap" );
  687. X#endif
  688. X#ifdef FPE_FLTDIV_TRAP 
  689. X    case FPE_FLTDIV_TRAP : abort ( "Floating/decimal division by zero trap" );
  690. X#endif
  691. X#ifdef FPE_FLTUND_TRAP 
  692. X    case FPE_FLTUND_TRAP : abort ( "Floating underflow trap" );
  693. X#endif
  694. X#ifdef FPE_DECOVF_TRAP 
  695. X    case FPE_DECOVF_TRAP : abort ( "Decimal overflow trap" );
  696. X#endif
  697. X#ifdef FPE_SUBRNG_TRAP 
  698. X    case FPE_SUBRNG_TRAP : abort ( "Subscript range trap" );
  699. X#endif
  700. X#ifdef FPE_FLTOVF_FAULT
  701. X    case FPE_FLTOVF_FAULT: abort ( "Floating overflow fault" );
  702. X#endif
  703. X#ifdef FPE_FLTDIV_FAULT
  704. X    case FPE_FLTDIV_FAULT: abort ( "Floating divide by zero fault" );
  705. X#endif
  706. X#ifdef FPE_FLTUND_FAULT
  707. X    case FPE_FLTUND_FAULT: abort ( "Floating underflow fault" );
  708. X#endif
  709. X    default              : abort ( "Floating exception" );
  710. X    }
  711. X}
  712. SHAR_EOF
  713. if test 3671 -ne "`wc -c < 'main.c'`"
  714. then
  715.     echo shar: error transmitting "'main.c'" '(should have been 3671 characters)'
  716. fi
  717. fi
  718. if test -f 'max.c'
  719. then
  720.     echo shar: will not over-write existing file "'max.c'"
  721. else
  722. echo extracting "'max.c'"
  723. sed 's/^X//' >max.c <<'SHAR_EOF'
  724. X/*
  725. X * Copyright (C) 1986   Alan Kent
  726. X *
  727. X * Permission is granted to freely distribute part or
  728. X * all of this code as long as it is not for profit
  729. X * and this message is retained in the code.
  730. X *
  731. X * No resposibility is taken for any damage or incorect
  732. X * results this program generates.
  733. X * 
  734. X */
  735. X
  736. X
  737. X#include <stdio.h>
  738. X#include "graph.h"
  739. X
  740. X
  741. Xdouble
  742. Xmax_fun ( table , from , to )
  743. Xtable_st *table;
  744. Xint from , to;
  745. X{
  746. X    int i;
  747. X    double val;
  748. X
  749. X    if ( table == NULL )
  750. X    abort ( "MAX requires at least a single column table" );
  751. X    if ( table->size < 1 ) {
  752. X    warn ( "MAX requires at least one value in table " );
  753. X    return ( 0.0 );
  754. X    }
  755. X    if ( to >= table->size )
  756. X    to = table->size - 1;
  757. X    val = table->data[from];
  758. X    for ( i = from + 1; i <= to; i++ )
  759. X    if ( table->data[i] > val )
  760. X        val = table->data[i];
  761. X    return ( val );
  762. X}
  763. X
  764. SHAR_EOF
  765. if test 823 -ne "`wc -c < 'max.c'`"
  766. then
  767.     echo shar: error transmitting "'max.c'" '(should have been 823 characters)'
  768. fi
  769. fi
  770. if test -f 'min.c'
  771. then
  772.     echo shar: will not over-write existing file "'min.c'"
  773. else
  774. echo extracting "'min.c'"
  775. sed 's/^X//' >min.c <<'SHAR_EOF'
  776. X/*
  777. X * Copyright (C) 1986   Alan Kent
  778. X *
  779. X * Permission is granted to freely distribute part or
  780. X * all of this code as long as it is not for profit
  781. X * and this message is retained in the code.
  782. X *
  783. X * No resposibility is taken for any damage or incorect
  784. X * results this program generates.
  785. X * 
  786. X */
  787. X
  788. X
  789. X#include <stdio.h>
  790. X#include "graph.h"
  791. X
  792. X
  793. Xdouble
  794. Xmin_fun ( table , from , to )
  795. Xtable_st *table;
  796. Xint from , to;
  797. X{
  798. X    int i;
  799. X    double val;
  800. X
  801. X    if ( table == NULL )
  802. X    abort ( "MIN requires at least a single column table" );
  803. X    if ( table->size < 1 ) {
  804. X    warn ( "MIN requires at least one value in table " );
  805. X    return ( 0.0 );
  806. X    }
  807. X    if ( to >= table->size )
  808. X    to = table->size - 1;
  809. X    val = table->data[from];
  810. X    for ( i = from + 1; i <= to; i++ )
  811. X    if ( table->data[i] < val )
  812. X        val = table->data[i];
  813. X    return ( val );
  814. X}
  815. X
  816. SHAR_EOF
  817. if test 823 -ne "`wc -c < 'min.c'`"
  818. then
  819.     echo shar: error transmitting "'min.c'" '(should have been 823 characters)'
  820. fi
  821. fi
  822. if test -f 'new.c'
  823. then
  824.     echo shar: will not over-write existing file "'new.c'"
  825. else
  826. echo extracting "'new.c'"
  827. sed 's/^X//' >new.c <<'SHAR_EOF'
  828. X/*
  829. X * Copyright (C) 1986   Alan Kent
  830. X *
  831. X * Permission is granted to freely distribute part or
  832. X * all of this code as long as it is not for profit
  833. X * and this message is retained in the code.
  834. X *
  835. X * No resposibility is taken for any damage or incorect
  836. X * results this program generates.
  837. X * 
  838. X */
  839. X
  840. X
  841. X#include <stdio.h>
  842. X
  843. X
  844. Xextern char *malloc ();
  845. X
  846. Xint bytes_allocated = 0;
  847. X
  848. X
  849. Xchar *
  850. Xnew ( size )
  851. Xint size;
  852. X{
  853. X    char *p;
  854. X    char buf[100];
  855. X
  856. X    if ( size < 1 )
  857. X    size = 1;
  858. X    p = malloc ( size );
  859. X    if ( p == NULL ) {
  860. X    sprintf ( buf ,
  861. X        "out of memory: request for %d bytes failed, %d allocated so far\n",
  862. X        size , bytes_allocated );
  863. X    abort ( buf );
  864. X    }
  865. X    bytes_allocated += size;
  866. X    return ( p );
  867. X}
  868. X
  869. X
  870. Xrelease ( mem )
  871. Xchar *mem;
  872. X{
  873. X    if ( mem == NULL )
  874. X    abort ( "Trying to free NULL pointer" );
  875. X    free ( mem );
  876. X}
  877. X
  878. SHAR_EOF
  879. if test 822 -ne "`wc -c < 'new.c'`"
  880. then
  881.     echo shar: error transmitting "'new.c'" '(should have been 822 characters)'
  882. fi
  883. fi
  884. if test -f 'newtable.c'
  885. then
  886.     echo shar: will not over-write existing file "'newtable.c'"
  887. else
  888. echo extracting "'newtable.c'"
  889. sed 's/^X//' >newtable.c <<'SHAR_EOF'
  890. X/*
  891. X * Copyright (C) 1986   Alan Kent
  892. X *
  893. X * Permission is granted to freely distribute part or
  894. X * all of this code as long as it is not for profit
  895. X * and this message is retained in the code.
  896. X *
  897. X * No resposibility is taken for any damage or incorect
  898. X * results this program generates.
  899. X * 
  900. X */
  901. X
  902. X
  903. X#include <stdio.h>
  904. X#include "graph.h"
  905. X
  906. X
  907. Xextern char *new ();
  908. X
  909. X
  910. Xtable_st *
  911. Xnew_table ( cols , rows )
  912. Xint cols , rows;
  913. X{
  914. X    table_st **pp;
  915. X    table_st *newtab;
  916. X
  917. X    newtab = NULL;
  918. X    pp = &newtab;
  919. X    while ( cols-- > 0 ) {
  920. X    (*pp) = (table_st *) new ( sizeof ( table_st ) );
  921. X    (*pp)->data = (double *) new ( sizeof ( double ) * rows );
  922. X    (*pp)->size = rows;
  923. X    (*pp)->next = NULL;
  924. X    pp = &(*pp)->next;
  925. X    }
  926. X    return ( newtab );
  927. X}
  928. X
  929. SHAR_EOF
  930. if test 725 -ne "`wc -c < 'newtable.c'`"
  931. then
  932.     echo shar: error transmitting "'newtable.c'" '(should have been 725 characters)'
  933. fi
  934. fi
  935. if test -f 'numcols.c'
  936. then
  937.     echo shar: will not over-write existing file "'numcols.c'"
  938. else
  939. echo extracting "'numcols.c'"
  940. sed 's/^X//' >numcols.c <<'SHAR_EOF'
  941. X/*
  942. X * Copyright (C) 1986   Alan Kent
  943. X *
  944. X * Permission is granted to freely distribute part or
  945. X * all of this code as long as it is not for profit
  946. X * and this message is retained in the code.
  947. X *
  948. X * No resposibility is taken for any damage or incorect
  949. X * results this program generates.
  950. X * 
  951. X */
  952. X
  953. X
  954. X#include <stdio.h>
  955. X#include "graph.h"
  956. X
  957. X
  958. Xnum_cols ( table )
  959. Xtable_st *table;
  960. X{
  961. X    int count;
  962. X    table_st *p;
  963. X
  964. X    count = 0;
  965. X    for ( p = table; p != NULL; p = p->next )
  966. X    count++;
  967. X    return ( count );
  968. X}
  969. X
  970. SHAR_EOF
  971. if test 502 -ne "`wc -c < 'numcols.c'`"
  972. then
  973.     echo shar: error transmitting "'numcols.c'" '(should have been 502 characters)'
  974. fi
  975. fi
  976. if test -f 'parmnode.c'
  977. then
  978.     echo shar: will not over-write existing file "'parmnode.c'"
  979. else
  980. echo extracting "'parmnode.c'"
  981. sed 's/^X//' >parmnode.c <<'SHAR_EOF'
  982. X/*
  983. X * Copyright (C) 1986   Alan Kent
  984. X *
  985. X * Permission is granted to freely distribute part or
  986. X * all of this code as long as it is not for profit
  987. X * and this message is retained in the code.
  988. X *
  989. X * No resposibility is taken for any damage or incorect
  990. X * results this program generates.
  991. X * 
  992. X */
  993. X
  994. X
  995. X#include <stdio.h>
  996. X#include "graph.h"
  997. X#include "y.tab.h"
  998. X
  999. X
  1000. Xextern char *new ();
  1001. X
  1002. X
  1003. Xparm_st *
  1004. Xparm_node ( ident , parm_type )
  1005. Xchar *ident;
  1006. Xint parm_type;
  1007. X{
  1008. X    parm_st *p;
  1009. X
  1010. X    p = (parm_st *) new ( sizeof ( parm_st ) );
  1011. X    p->ident = ident;
  1012. X    p->parm_type = parm_type;
  1013. X    p->next = NULL;
  1014. X    if ( ident != NULL ) {
  1015. X    if ( parm_type == TABLE )
  1016. X        tab_declare ( ident , NULL );
  1017. X    else
  1018. X        var_declare ( ident , (double)0.0 );
  1019. X    }
  1020. X    return ( p );
  1021. X}
  1022. SHAR_EOF
  1023. if test 749 -ne "`wc -c < 'parmnode.c'`"
  1024. then
  1025.     echo shar: error transmitting "'parmnode.c'" '(should have been 749 characters)'
  1026. fi
  1027. fi
  1028. if test -f 'printtab.c'
  1029. then
  1030.     echo shar: will not over-write existing file "'printtab.c'"
  1031. else
  1032. echo extracting "'printtab.c'"
  1033. sed 's/^X//' >printtab.c <<'SHAR_EOF'
  1034. X/*
  1035. X * Copyright (C) 1986   Alan Kent
  1036. X *
  1037. X * Permission is granted to freely distribute part or
  1038. X * all of this code as long as it is not for profit
  1039. X * and this message is retained in the code.
  1040. X *
  1041. X * No resposibility is taken for any damage or incorect
  1042. X * results this program generates.
  1043. X * 
  1044. X */
  1045. X
  1046. X
  1047. X#include <stdio.h>
  1048. X#include "graph.h"
  1049. X
  1050. X
  1051. Xextern double eval ();
  1052. X
  1053. X
  1054. X
  1055. Xprint_table ( table , filename , mode )
  1056. Xtable_st *table;
  1057. Xchar *filename , *mode;
  1058. X{
  1059. X    table_st *p;
  1060. X    int i;
  1061. X    int cols;
  1062. X    FILE *fp;
  1063. X
  1064. X
  1065. X    if ( filename == NULL )
  1066. X    fp = stdout;
  1067. X    else {
  1068. X    fp = fopen ( filename , mode );
  1069. X    if ( fp == NULL )
  1070. X        abort ( "failed to open print file '%s'" , filename );
  1071. X    }
  1072. X    if ( table == NULL ) {
  1073. X    fprintf ( fp , "empty table\n" );
  1074. X    }
  1075. X    else {
  1076. X    cols = 0;
  1077. X    for ( p = table; p != NULL; p = p->next )
  1078. X        cols++;
  1079. X    for ( i = 0; i < table->size; i++ ) {
  1080. X        for ( p = table; p != NULL; p = p->next ) {
  1081. X        fprintf ( fp , "%g" , p->data[i] );
  1082. X        if ( p->next != NULL )
  1083. X            fprintf ( fp , "\t" );
  1084. X        }
  1085. X        fprintf ( fp , "\n" );
  1086. X    }
  1087. X    }
  1088. X    if ( fp != stdout )
  1089. X    fclose ( fp );
  1090. X}
  1091. X
  1092. X
  1093. X
  1094. Xprint_expr ( value , filename , mode )
  1095. Xdouble value;
  1096. Xchar *filename , *mode;
  1097. X{
  1098. X    FILE *fp;
  1099. X
  1100. X    if ( filename == NULL )
  1101. X    fp = stdout;
  1102. X    else {
  1103. X    fp = fopen ( filename , mode );
  1104. X    if ( fp == NULL )
  1105. X        abort ( "failed to open print file '%s'" , filename );
  1106. X    }
  1107. X    fprintf ( fp , "%g\n" , value );
  1108. X    if ( fp != stdout )
  1109. X    fclose ( fp );
  1110. X}
  1111. X
  1112. X
  1113. X
  1114. Xprint_string ( string , filename , mode )
  1115. Xchar *string;
  1116. Xchar *filename , *mode;
  1117. X{
  1118. X    FILE *fp;
  1119. X
  1120. X    if ( filename == NULL )
  1121. X    fp = stdout;
  1122. X    else {
  1123. X    fp = fopen ( filename , mode );
  1124. X    if ( fp == NULL )
  1125. X        abort ( "failed to open print file '%s'" , filename );
  1126. X    }
  1127. X    fprintf ( fp , "%s\n" , string );
  1128. X    if ( fp != stdout )
  1129. X    fclose ( fp );
  1130. X}
  1131. X
  1132. SHAR_EOF
  1133. if test 1784 -ne "`wc -c < 'printtab.c'`"
  1134. then
  1135.     echo shar: error transmitting "'printtab.c'" '(should have been 1784 characters)'
  1136. fi
  1137. fi
  1138. if test -f 'project.c'
  1139. then
  1140.     echo shar: will not over-write existing file "'project.c'"
  1141. else
  1142. echo extracting "'project.c'"
  1143. sed 's/^X//' >project.c <<'SHAR_EOF'
  1144. X/*
  1145. X * Copyright (C) 1986   Alan Kent
  1146. X *
  1147. X * Permission is granted to freely distribute part or
  1148. X * all of this code as long as it is not for profit
  1149. X * and this message is retained in the code.
  1150. X *
  1151. X * No resposibility is taken for any damage or incorect
  1152. X * results this program generates.
  1153. X * 
  1154. X */
  1155. X
  1156. X
  1157. X#include <stdio.h>
  1158. X#include "graph.h"
  1159. X
  1160. X
  1161. Xextern table_st *new_table ();
  1162. Xextern double eval ();
  1163. X
  1164. X
  1165. Xtable_st *
  1166. Xproject ( table , attr_expr_list )
  1167. Xtable_st *table;
  1168. Xexpr_list_st *attr_expr_list;
  1169. X{
  1170. X    table_st *newtab , *p;
  1171. X    expr_list_st *list;
  1172. X    int count;
  1173. X    int i;
  1174. X
  1175. X    if ( table == NULL )
  1176. X    abort ( "cannot project on an empty table" );
  1177. X    count = 0;
  1178. X    for ( list = attr_expr_list; list != NULL; list = list->next )
  1179. X    count++;
  1180. X    newtab = new_table ( count , table->size );
  1181. X    for ( list = attr_expr_list , p = newtab; list != NULL; list = list->next , p = p->next ) {
  1182. X    for ( i = 0; i < table->size; i++ )
  1183. X        p->data[i] = eval ( table , i , list->expr );
  1184. X    }
  1185. X    free_table ( table );
  1186. X    return ( newtab );
  1187. X}
  1188. X
  1189. SHAR_EOF
  1190. if test 1018 -ne "`wc -c < 'project.c'`"
  1191. then
  1192.     echo shar: error transmitting "'project.c'" '(should have been 1018 characters)'
  1193. fi
  1194. fi
  1195. if test -f 'readtab.c'
  1196. then
  1197.     echo shar: will not over-write existing file "'readtab.c'"
  1198. else
  1199. echo extracting "'readtab.c'"
  1200. sed 's/^X//' >readtab.c <<'SHAR_EOF'
  1201. X/*
  1202. X * Copyright (C) 1986   Alan Kent
  1203. X *
  1204. X * Permission is granted to freely distribute part or
  1205. X * all of this code as long as it is not for profit
  1206. X * and this message is retained in the code.
  1207. X *
  1208. X * No resposibility is taken for any damage or incorect
  1209. X * results this program generates.
  1210. X * 
  1211. X */
  1212. X
  1213. X
  1214. X#include <stdio.h>
  1215. X#include <ctype.h>
  1216. X#include <math.h>
  1217. X#include "graph.h"
  1218. X
  1219. X
  1220. X#define BUF_SIZE    512
  1221. X
  1222. X
  1223. Xextern double log10 ();
  1224. Xextern double pow ();
  1225. Xextern table_st *new_table ();
  1226. X
  1227. X
  1228. Xtable_st *
  1229. Xread_table ( filename , num_cols , num_rows )
  1230. Xchar *filename;
  1231. Xint num_cols , num_rows;
  1232. X{
  1233. X    char *skip_blanks ();
  1234. X    char *scan_value ();
  1235. X
  1236. X    char buf[ BUF_SIZE ];
  1237. X    char *p;
  1238. X    FILE *fp;
  1239. X    int rows , cols , i;
  1240. X    table_st *table , *tp;
  1241. X    double val;
  1242. X
  1243. X
  1244. X    /* first, open the file */
  1245. X
  1246. X    if ( ( fp = fopen ( filename , "r" ) ) == NULL )
  1247. X    abort ( "failed to open file '%s'" , filename );
  1248. X    
  1249. X    if ( num_cols < 0 || num_rows < 0 ) {
  1250. X
  1251. X    /* pass one of file: count rows and cols */
  1252. X
  1253. X    rows = 0;
  1254. X    cols = 0;
  1255. X    do {
  1256. X        if ( fgets ( buf , BUF_SIZE , fp ) == NULL ) {
  1257. X        /* empty data file */
  1258. X        fclose ( fp );
  1259. X        return ( NULL );
  1260. X        }
  1261. X    } while ( *skip_blanks ( buf ) == '\0' );
  1262. X    p = skip_blanks ( buf );
  1263. X    while ( *p != '\0' ) {
  1264. X        cols++;
  1265. X        p = scan_value ( p , &val );
  1266. X        if ( p == NULL )
  1267. X        abort ( "Data file '%s' contains non-numeric data" , filename );
  1268. X        p = skip_blanks ( p );
  1269. X    }
  1270. X    rows++;
  1271. X    while ( fgets ( buf , BUF_SIZE , fp ) != NULL ) {
  1272. X        if ( *skip_blanks ( buf ) != '\0' )
  1273. X        rows++;
  1274. X    }
  1275. X
  1276. X    /* allocate and read new table */
  1277. X
  1278. X    rewind ( fp );
  1279. X    }
  1280. X    else {
  1281. X    rows = num_rows;
  1282. X    cols = num_cols;
  1283. X    }
  1284. X
  1285. X    /*
  1286. X    printf ( "Data file '%s' contains %d columns and %d rows of data\n" ,
  1287. X    filename , cols , rows );
  1288. X    */
  1289. X
  1290. X    table = new_table ( cols , rows );
  1291. X    i = 0;
  1292. X    while ( fgets ( buf , BUF_SIZE , fp ) != NULL  &&  i < rows ) {
  1293. X    if ( *skip_blanks ( buf ) != '\0' ) {
  1294. X        tp = table;
  1295. X        p = skip_blanks ( buf );
  1296. X        while ( *p != '\0' ) {
  1297. X        if ( tp == NULL )
  1298. X            break;
  1299. X        p = scan_value ( p , &val );
  1300. X        if ( p == NULL )
  1301. X            abort ( "illegal data on data file '%s'" , filename );
  1302. X        p = skip_blanks ( p );
  1303. X        tp->data[i] = val;
  1304. X        tp = tp->next;
  1305. X        }
  1306. X        i++;
  1307. X        if ( tp != NULL )
  1308. X        abort ( "line too short in data file '%s'" , filename );
  1309. X    }
  1310. X    }
  1311. X
  1312. X    /* if table size got from parameters, it is possible that the table */
  1313. X    /* allocated has more rows than was specified (cols are reported as */
  1314. X    /* an error). This is alright, but the table should be shrunk in size. */
  1315. X    /* note that as malloc() does not care about our table size, it does not */
  1316. X    /* matter if the size field is larger than the actual table. */
  1317. X
  1318. X    for ( tp = table; tp != NULL; tp = tp->next )
  1319. X    tp->size = i;
  1320. X
  1321. X    fclose ( fp );
  1322. X    return ( table );
  1323. X}
  1324. X
  1325. X
  1326. X
  1327. Xchar *
  1328. Xscan_value ( in_str , pval )
  1329. Xchar *in_str;
  1330. Xdouble *pval;
  1331. X{
  1332. X    register char *str;
  1333. X    int sign;
  1334. X    int num_digits;
  1335. X    register int exponent;
  1336. X    int exp2;
  1337. X    double val;
  1338. X
  1339. X
  1340. X    str = in_str;    /* register variable for SPEED */
  1341. X
  1342. X    /* get leading +/- sign */
  1343. X
  1344. X    sign = 1;
  1345. X    if ( *str == '+' )
  1346. X    str++;
  1347. X    else if ( *str == '-' ) {
  1348. X    str++;
  1349. X    sign = -1;
  1350. X    }
  1351. X
  1352. X    /* get digit string */
  1353. X
  1354. X    num_digits = 0;
  1355. X    val = 0.0;
  1356. X    exponent = 0;
  1357. X    while ( isdigit ( *str ) ) {
  1358. X    val = val * 10.0 + ( *str - '0' );
  1359. X    str++;
  1360. X    num_digits++;
  1361. X    }
  1362. X    if ( *str == '.' ) {
  1363. X    str++;
  1364. X    while ( isdigit ( *str ) ) {
  1365. X        val = val * 10.0 + ( *str - '0' );
  1366. X        exponent--;
  1367. X        str++;
  1368. X        num_digits++;
  1369. X    }
  1370. X    }
  1371. X
  1372. X    if ( num_digits == 0 )
  1373. X    return ( NULL );
  1374. X    
  1375. X    if ( sign < 0 )
  1376. X    val = -val;
  1377. X    
  1378. X    if ( *str == 'e'  ||  *str == 'E' ) {
  1379. X    str++;
  1380. X    sign = 1;
  1381. X    if ( *str == '+' )
  1382. X        str++;
  1383. X    else if ( *str == '-' ) {
  1384. X        str++;
  1385. X        sign = -1;
  1386. X    }
  1387. X    if ( ! isdigit ( *str ) )
  1388. X        return ( NULL );
  1389. X    exp2 = 0;
  1390. X    while ( isdigit ( *str ) ) {
  1391. X        exp2 = exp2 * 10 + ( *str - '0' );
  1392. X        str++;
  1393. X    }
  1394. X    if ( sign < 0 )
  1395. X        exp2 = -exp2;
  1396. X    exponent += exp2;
  1397. X    }
  1398. X
  1399. X    /* now, merge the value and the exponent */
  1400. X    /* anyone know a PORTABLE and fast way of doing this accurately? */
  1401. X    /* Using the log functions can introduce errors */
  1402. X
  1403. X    if ( exponent < -12  ||  exponent > 12 ) {
  1404. X    /* For speed, use pow for large exponents */
  1405. X    val *= pow ( 10.0 , (double)exponent );
  1406. X    }
  1407. X    else {
  1408. X    while ( exponent < 0 ) {
  1409. X        val *= 0.1;
  1410. X        exponent++;
  1411. X    }
  1412. X    while ( exponent > 0 ) {
  1413. X        val *= 10.0;
  1414. X        exponent--;
  1415. X    }
  1416. X    }
  1417. X
  1418. X    *pval = val;
  1419. X
  1420. X#ifdef USING_ATOF
  1421. X    /* this requires scanning the string twice and does not detect */
  1422. X    /* errors at all */
  1423. X    str = in_str;
  1424. X    *pval = atof ( str );
  1425. X    while ( *str != '\0'  &&  ! isspace ( *str ) )
  1426. X    str++;
  1427. X#endif
  1428. X
  1429. X    return ( str );
  1430. X}
  1431. X
  1432. X
  1433. X
  1434. Xstatic char *
  1435. Xskip_blanks ( str )
  1436. Xchar *str;
  1437. X{
  1438. X    while ( isspace ( *str ) )
  1439. X    str++;
  1440. X    if ( *str == '#' )
  1441. X    while ( *str != '\0' )
  1442. X        str++;
  1443. X    return ( str );
  1444. X}
  1445. X
  1446. SHAR_EOF
  1447. if test 4816 -ne "`wc -c < 'readtab.c'`"
  1448. then
  1449.     echo shar: error transmitting "'readtab.c'" '(should have been 4816 characters)'
  1450. fi
  1451. fi
  1452. if test -f 'reset.c'
  1453. then
  1454.     echo shar: will not over-write existing file "'reset.c'"
  1455. else
  1456. echo extracting "'reset.c'"
  1457. sed 's/^X//' >reset.c <<'SHAR_EOF'
  1458. X/*
  1459. X * Copyright (C) 1986   Alan Kent
  1460. X *
  1461. X * Permission is granted to freely distribute part or
  1462. X * all of this code as long as it is not for profit
  1463. X * and this message is retained in the code.
  1464. X *
  1465. X * No resposibility is taken for any damage or incorect
  1466. X * results this program generates.
  1467. X * 
  1468. X */
  1469. X
  1470. X
  1471. X#include <stdio.h>
  1472. X#include "graph.h"
  1473. X#include "y.tab.h"
  1474. X
  1475. Xextern char *PROG_NAME;
  1476. Xextern axis_st xaxis;
  1477. Xextern axis_st yaxis;
  1478. Xextern graph_st graph[];
  1479. Xextern int num_graphs;
  1480. Xextern char *graph_label;
  1481. Xextern int horiz_legend;
  1482. Xextern int vert_legend;
  1483. X
  1484. X
  1485. Xreset_graphs ()
  1486. X{
  1487. X    int i;
  1488. X
  1489. X    xaxis.format = yaxis.format = "%.1f";
  1490. X    xaxis.user_format = yaxis.user_format = NULL;
  1491. X    xaxis.label = yaxis.label = "";
  1492. X    xaxis.scale = yaxis.scale = AUTO;
  1493. X    xaxis.frame = yaxis.frame = GRID;
  1494. X    xaxis.linear = yaxis.linear = LINEAR;
  1495. X    xaxis.auto_tick_size = yaxis.auto_tick_size = 1;
  1496. X    xaxis.range.min = yaxis.range.min = 0.0;
  1497. X    xaxis.range.max = yaxis.range.max = -1.0;
  1498. X    xaxis.interval = yaxis.interval = NULL;
  1499. X
  1500. X    for ( i = 0; i < num_graphs; i++ ) {
  1501. X    if ( graph[i].label != NULL )
  1502. X        release ( graph[i].label );
  1503. X    if ( graph[i].legend != NULL )
  1504. X        release ( graph[i].legend );
  1505. X    free_table ( graph[i].table );
  1506. X    }
  1507. X
  1508. X    if ( graph_label != NULL ) {
  1509. X    release ( graph_label );
  1510. X    graph_label = NULL;
  1511. X    }
  1512. X
  1513. X    num_graphs = 0;
  1514. X    horiz_legend = RIGHT;
  1515. X    vert_legend = TOP;
  1516. X}
  1517. X
  1518. SHAR_EOF
  1519. if test 1380 -ne "`wc -c < 'reset.c'`"
  1520. then
  1521.     echo shar: error transmitting "'reset.c'" '(should have been 1380 characters)'
  1522. fi
  1523. fi
  1524. if test -f 'saveload.c'
  1525. then
  1526.     echo shar: will not over-write existing file "'saveload.c'"
  1527. else
  1528. echo extracting "'saveload.c'"
  1529. sed 's/^X//' >saveload.c <<'SHAR_EOF'
  1530. X/*
  1531. X * Copyright (C) 1986   Alan Kent
  1532. X *
  1533. X * Permission is granted to freely distribute part or
  1534. X * all of this code as long as it is not for profit
  1535. X * and this message is retained in the code.
  1536. X *
  1537. X * No resposibility is taken for any damage or incorect
  1538. X * results this program generates.
  1539. X * 
  1540. X */
  1541. X
  1542. X
  1543. X#include <stdio.h>
  1544. X#include "graph.h"
  1545. X
  1546. X
  1547. Xextern struct table_st *new_table ();
  1548. X
  1549. X
  1550. Xsave_table ( filename , table )
  1551. Xchar *filename;
  1552. Xtable_st *table;
  1553. X{
  1554. X    table_st *p;
  1555. X    int i;
  1556. X    int cols;
  1557. X    FILE *fp;
  1558. X
  1559. X
  1560. X    if ( filename == NULL ) {
  1561. X    fp = stdout;
  1562. X    filename = "stdout";
  1563. X    }
  1564. X    else {
  1565. X    fp = fopen ( filename , "w" );
  1566. X    if ( fp == NULL )
  1567. X        abort ( "failed to open save file '%s'" , filename );
  1568. X    }
  1569. X    if ( table == NULL ) {
  1570. X    outint ( fp , 0 , filename );    /* cols */
  1571. X    outint ( fp , 0 , filename );    /* rows */
  1572. X    }
  1573. X    else {
  1574. X    cols = num_cols ( table );
  1575. X    outint ( fp , cols );
  1576. X    outint ( fp , table->size );
  1577. X    for ( p = table; p != NULL; p = p->next )
  1578. X        if ( fwrite ( p->data , sizeof ( double ) , p->size , fp ) != p->size )
  1579. X        abort ( "Write error on '%s'" , filename );
  1580. X    }
  1581. X    if ( fp != stdout )
  1582. X    fclose ( fp );
  1583. X}
  1584. X
  1585. X
  1586. Xoutint ( fp , val , filename )
  1587. XFILE *fp;
  1588. Xint val;
  1589. Xchar *filename;
  1590. X{
  1591. X    if ( fwrite ( &val , sizeof ( val ) , 1 , fp ) != 1 )
  1592. X    abort ( "Error when writing to '%s'" , filename );
  1593. X}
  1594. X
  1595. X
  1596. X
  1597. Xstruct table_st *
  1598. Xload_table ( filename )
  1599. Xchar *filename;
  1600. X{
  1601. X    FILE *fp;
  1602. X    struct table_st *p , *tab;
  1603. X    int cols , rows;
  1604. X
  1605. X    if ( filename == NULL ) {
  1606. X    fp = stdin;
  1607. X    filename = "stdin";
  1608. X    }
  1609. X    else {
  1610. X    fp = fopen ( filename , "r" );
  1611. X    if ( fp == NULL )
  1612. X        abort ( "failed to open file '%s' to load it" , filename );
  1613. X    }
  1614. X    if ( fread ( &cols , sizeof ( int ) , 1 , fp ) != 1 )
  1615. X    abort ( "Error when reading '%s'" , filename );
  1616. X    if ( fread ( &rows , sizeof ( int ) , 1 , fp ) != 1 )
  1617. X    abort ( "Error when reading '%s'" , filename );
  1618. X    tab = new_table ( cols , rows );
  1619. X    for ( p = tab; p != NULL; p = p->next ) {
  1620. X    if ( fread ( p->data , sizeof ( double ) , p->size , fp ) != p->size )
  1621. X        abort ( "Read error on '%s' when loading file" , filename );
  1622. X    }
  1623. X    if ( fp != stdin )
  1624. X    fclose ( fp );
  1625. X    return ( tab );
  1626. X}
  1627. SHAR_EOF
  1628. if test 2139 -ne "`wc -c < 'saveload.c'`"
  1629. then
  1630.     echo shar: error transmitting "'saveload.c'" '(should have been 2139 characters)'
  1631. fi
  1632. fi
  1633. if test -f 'select.c'
  1634. then
  1635.     echo shar: will not over-write existing file "'select.c'"
  1636. else
  1637. echo extracting "'select.c'"
  1638. sed 's/^X//' >select.c <<'SHAR_EOF'
  1639. X/*
  1640. X * Copyright (C) 1986   Alan Kent
  1641. X *
  1642. X * Permission is granted to freely distribute part or
  1643. X * all of this code as long as it is not for profit
  1644. X * and this message is retained in the code.
  1645. X *
  1646. X * No resposibility is taken for any damage or incorect
  1647. X * results this program generates.
  1648. X * 
  1649. X */
  1650. X
  1651. X
  1652. X#include <stdio.h>
  1653. X#include "graph.h"
  1654. X
  1655. X
  1656. Xtable_st *
  1657. Xselect ( table , attr_expr )
  1658. Xtable_st *table;
  1659. Xattr_st *attr_expr;
  1660. X{
  1661. X    double eval ();
  1662. X
  1663. X    int i , j;
  1664. X
  1665. X
  1666. X    /* if any line is not selected, simply copy all following lines */
  1667. X    /* back over it. This means the array may be actually larger than */
  1668. X    /* necessary for the data, but it is a lot easier!!! */
  1669. X
  1670. X    j = 0;
  1671. X    for ( i = 0; i < table->size; i++ ) {
  1672. X    if ( eval ( table , i , attr_expr ) != 0.0 ) { /* True */
  1673. X        /* save copy */
  1674. X        copy_entry ( table , j , i );
  1675. X        j++;
  1676. X    }
  1677. X    }
  1678. X    table->size -= i - j;
  1679. X    return ( table );
  1680. X}
  1681. X
  1682. SHAR_EOF
  1683. if test 895 -ne "`wc -c < 'select.c'`"
  1684. then
  1685.     echo shar: error transmitting "'select.c'" '(should have been 895 characters)'
  1686. fi
  1687. fi
  1688. if test -f 'sort.c'
  1689. then
  1690.     echo shar: will not over-write existing file "'sort.c'"
  1691. else
  1692. echo extracting "'sort.c'"
  1693. sed 's/^X//' >sort.c <<'SHAR_EOF'
  1694. X/*
  1695. X * Copyright (C) 1986   Alan Kent
  1696. X *
  1697. X * Permission is granted to freely distribute part or
  1698. X * all of this code as long as it is not for profit
  1699. X * and this message is retained in the code.
  1700. X *
  1701. X * No resposibility is taken for any damage or incorect
  1702. X * results this program generates.
  1703. X * 
  1704. X */
  1705. X
  1706. X
  1707. X#include <stdio.h>
  1708. X#include "graph.h"
  1709. X
  1710. X
  1711. Xtable_st *
  1712. Xsort ( table , attr )
  1713. Xtable_st *table;
  1714. Xint attr;
  1715. X{
  1716. X    int i , j;
  1717. X    table_st *pcol , *p;
  1718. X    double min;
  1719. X    int min_index;
  1720. X    double temp;
  1721. X
  1722. X    if ( attr < 1 )
  1723. X    return ( table );
  1724. X    for ( pcol = table , i = 1; pcol != NULL && i < attr; pcol = pcol->next , i++ );
  1725. X    if ( pcol == NULL )
  1726. X    abort ( "SORT by non-existant column" );
  1727. X
  1728. X    /* quick sort */
  1729. X
  1730. X    quick ( table , pcol->data , 0 , table->size - 1 );
  1731. X
  1732. X    return ( table );
  1733. X}
  1734. X
  1735. X
  1736. Xstatic
  1737. Xquick ( table , data , low , high )
  1738. Xtable_st *table;
  1739. Xdouble *data;
  1740. Xint low , high;
  1741. X{
  1742. X    int i , j;
  1743. X    double sample , temp;
  1744. X    register table_st *p;
  1745. X
  1746. X    if ( low == high )
  1747. X    return;
  1748. X    i = low + 1;
  1749. X    j = high;
  1750. X    sample = data[ low ];
  1751. X    while ( i < j ) {
  1752. X    while ( i < j  &&  data[ i ] <= sample )
  1753. X        i++;
  1754. X    while ( j > i  &&  data[ j ] > sample )
  1755. X        j--;
  1756. X    
  1757. X    if ( i < j ) {
  1758. X
  1759. X        /* swap ith and jth entry */
  1760. X
  1761. X        for ( p = table; p != NULL; p = p->next ) {
  1762. X        temp = p->data[i];
  1763. X        p->data[i] = p->data[j];
  1764. X        p->data[j] = temp;
  1765. X        }
  1766. X    }
  1767. X    }
  1768. X
  1769. X    if ( data[i] > sample )
  1770. X    i--;
  1771. X    else
  1772. X    j++;
  1773. X    if ( data[i] < sample ) {    /* sample is data[low] */
  1774. X    for ( p = table; p != NULL; p = p->next ) {
  1775. X        temp = p->data[i];
  1776. X        p->data[i] = p->data[low];
  1777. X        p->data[low] = temp;
  1778. X    }
  1779. X    }
  1780. X    i--;
  1781. X
  1782. X    /* sort the new halves of the array */
  1783. X
  1784. X    if ( i > low )
  1785. X    quick ( table , data , low , i );
  1786. X    if ( j < high )
  1787. X    quick ( table , data , j , high );
  1788. X}
  1789. X
  1790. SHAR_EOF
  1791. if test 1757 -ne "`wc -c < 'sort.c'`"
  1792. then
  1793.     echo shar: error transmitting "'sort.c'" '(should have been 1757 characters)'
  1794. fi
  1795. fi
  1796. if test -f 'sum.c'
  1797. then
  1798.     echo shar: will not over-write existing file "'sum.c'"
  1799. else
  1800. echo extracting "'sum.c'"
  1801. sed 's/^X//' >sum.c <<'SHAR_EOF'
  1802. X/*
  1803. X * Copyright (C) 1986   Alan Kent
  1804. X *
  1805. X * Permission is granted to freely distribute part or
  1806. X * all of this code as long as it is not for profit
  1807. X * and this message is retained in the code.
  1808. X *
  1809. X * No resposibility is taken for any damage or incorect
  1810. X * results this program generates.
  1811. X * 
  1812. X */
  1813. X
  1814. X
  1815. X#include <stdio.h>
  1816. X#include "graph.h"
  1817. X
  1818. X
  1819. Xdouble
  1820. Xsum_fun ( table , from , to )
  1821. Xtable_st *table;
  1822. Xint from , to;
  1823. X{
  1824. X    int i;
  1825. X    double val;
  1826. X
  1827. X    if ( table == NULL )
  1828. X    abort ( "SUM requires at least a single column table" );
  1829. X    if ( table->size < 1 ) {
  1830. X    warn ( "SUM requires at least one value in table " );
  1831. X    return ( 0.0 );
  1832. X    }
  1833. X    if ( to >= table->size )
  1834. X    to = table->size - 1;
  1835. X    val = 0.0;
  1836. X    for ( i = from; i <= to; i++ )
  1837. X    val += table->data[i];
  1838. X    return ( val );
  1839. X}
  1840. X
  1841. SHAR_EOF
  1842. if test 773 -ne "`wc -c < 'sum.c'`"
  1843. then
  1844.     echo shar: error transmitting "'sum.c'" '(should have been 773 characters)'
  1845. fi
  1846. fi
  1847. if test -f 'tabdeclr.c'
  1848. then
  1849.     echo shar: will not over-write existing file "'tabdeclr.c'"
  1850. else
  1851. echo extracting "'tabdeclr.c'"
  1852. sed 's/^X//' >tabdeclr.c <<'SHAR_EOF'
  1853. X/*
  1854. X * Copyright (C) 1986   Alan Kent
  1855. X *
  1856. X * Permission is granted to freely distribute part or
  1857. X * all of this code as long as it is not for profit
  1858. X * and this message is retained in the code.
  1859. X *
  1860. X * No resposibility is taken for any damage or incorect
  1861. X * results this program generates.
  1862. X * 
  1863. X */
  1864. X
  1865. X
  1866. X#include <stdio.h>
  1867. X#include "graph.h"
  1868. X
  1869. X
  1870. X#define MAX_DEC        50
  1871. X
  1872. X
  1873. Xextern table_st *copy_of_table ();
  1874. X
  1875. X
  1876. Xstatic struct declare_st {
  1877. X    char *name;
  1878. X    table_st *table;
  1879. X} dec [ MAX_DEC ];
  1880. X
  1881. Xstatic int num_dec;
  1882. X
  1883. X
  1884. X
  1885. Xpdef_tab ()
  1886. X{
  1887. X    return;
  1888. X}
  1889. X
  1890. X
  1891. X
  1892. Xtab_declare ( name , table )
  1893. Xchar *name;
  1894. Xtable_st *table;
  1895. X{
  1896. X    int i;
  1897. X
  1898. X    for ( i = 0; i < num_dec; i++ ) {
  1899. X    if ( strcmp ( name , dec[i].name ) == 0 ) {
  1900. X        free_table ( dec[i].table );
  1901. X        dec[i].table = table;
  1902. X        return;
  1903. X    }
  1904. X    }
  1905. X    if ( num_dec >= MAX_DEC )
  1906. X    abort ( "Internal array overflow - too many tables declared" );
  1907. X    dec[num_dec].name = name;
  1908. X    dec[num_dec].table = table;
  1909. X    num_dec++;
  1910. X}
  1911. X
  1912. X
  1913. X
  1914. X
  1915. Xtable_st *
  1916. Xtab_lookup ( name )
  1917. Xchar *name;
  1918. X{
  1919. X    int i , cols;
  1920. X    table_st *table , *ftp , *ttp , *p;
  1921. X
  1922. X    for ( i = 0; i < num_dec; i++ ) {
  1923. X    if ( strcmp ( dec[i].name , name ) == 0 ) {
  1924. X        return ( copy_of_table ( dec[i].table ) );
  1925. X    }
  1926. X    }
  1927. X    abort ( "Undefined table '%s' referenced" , name );
  1928. X    return ( NULL );
  1929. X}
  1930. X
  1931. X
  1932. X
  1933. Xis_tab_ident ( name )
  1934. Xchar *name;
  1935. X{
  1936. X    int i;
  1937. X
  1938. X    for ( i = 0; i < num_dec; i++ ) {
  1939. X    if ( strcmp ( dec[i].name , name ) == 0 ) {
  1940. X        return ( 1 );
  1941. X    }
  1942. X    }
  1943. X    return ( 0 );
  1944. X}
  1945. X
  1946. X
  1947. SHAR_EOF
  1948. if test 1455 -ne "`wc -c < 'tabdeclr.c'`"
  1949. then
  1950.     echo shar: error transmitting "'tabdeclr.c'" '(should have been 1455 characters)'
  1951. fi
  1952. fi
  1953. if test -f 'tabnode.c'
  1954. then
  1955.     echo shar: will not over-write existing file "'tabnode.c'"
  1956. else
  1957. echo extracting "'tabnode.c'"
  1958. sed 's/^X//' >tabnode.c <<'SHAR_EOF'
  1959. X/*
  1960. X * Copyright (C) 1986   Alan Kent
  1961. X *
  1962. X * Permission is granted to freely distribute part or
  1963. X * all of this code as long as it is not for profit
  1964. X * and this message is retained in the code.
  1965. X *
  1966. X * No resposibility is taken for any damage or incorect
  1967. X * results this program generates.
  1968. X * 
  1969. X */
  1970. X
  1971. X
  1972. X#include <stdio.h>
  1973. X#include "graph.h"
  1974. X
  1975. X
  1976. X
  1977. Xextern char *new ();
  1978. X
  1979. X
  1980. Xtnode_st *
  1981. Xtab_node ( operator )
  1982. Xint operator;
  1983. X{
  1984. X    tnode_st *p;
  1985. X
  1986. X    p = (tnode_st *) new ( sizeof ( tnode_st ) );
  1987. X    p->operator = operator;
  1988. X    return ( p );
  1989. X}
  1990. SHAR_EOF
  1991. if test 524 -ne "`wc -c < 'tabnode.c'`"
  1992. then
  1993.     echo shar: error transmitting "'tabnode.c'" '(should have been 524 characters)'
  1994. fi
  1995. fi
  1996. if test -f 'vardeclr.c'
  1997. then
  1998.     echo shar: will not over-write existing file "'vardeclr.c'"
  1999. else
  2000. echo extracting "'vardeclr.c'"
  2001. sed 's/^X//' >vardeclr.c <<'SHAR_EOF'
  2002. X/*
  2003. X * Copyright (C) 1986   Alan Kent
  2004. X *
  2005. X * Permission is granted to freely distribute part or
  2006. X * all of this code as long as it is not for profit
  2007. X * and this message is retained in the code.
  2008. X *
  2009. X * No resposibility is taken for any damage or incorect
  2010. X * results this program generates.
  2011. X * 
  2012. X */
  2013. X
  2014. X
  2015. X#include <stdio.h>
  2016. X#include <math.h>
  2017. X#include "graph.h"
  2018. X
  2019. X
  2020. Xextern double eval ();
  2021. X
  2022. X
  2023. X#define MAX_DEC        50
  2024. X
  2025. X
  2026. Xstatic struct declare_st {
  2027. X    char *name;
  2028. X    double value;
  2029. X} dec [ MAX_DEC ];
  2030. X
  2031. Xstatic int num_dec;
  2032. X
  2033. X
  2034. X
  2035. Xpdef_var ()
  2036. X{
  2037. X    var_declare ( "infinity" , HUGE );
  2038. X}
  2039. X
  2040. X
  2041. X
  2042. Xvar_declare ( name , value )
  2043. Xchar *name;
  2044. Xdouble value;
  2045. X{
  2046. X    int i;
  2047. X
  2048. X    for ( i = 0; i < num_dec; i++ ) {
  2049. X    if ( strcmp ( name , dec[i].name ) == 0 ) {
  2050. X        dec[i].value = value;
  2051. X        return;
  2052. X    }
  2053. X    }
  2054. X    if ( num_dec >= MAX_DEC )
  2055. X    abort ( "Internal array overflow - too many variables declared" );
  2056. X    dec[num_dec].name = name;
  2057. X    dec[num_dec].value = value;
  2058. X    num_dec++;
  2059. X}
  2060. X
  2061. X
  2062. X
  2063. X
  2064. Xdouble
  2065. Xvar_lookup ( name )
  2066. Xchar *name;
  2067. X{
  2068. X    int i;
  2069. X
  2070. X    for ( i = 0; i < num_dec; i++ ) {
  2071. X    if ( strcmp ( dec[i].name , name ) == 0 ) {
  2072. X        return ( dec[i].value );
  2073. X    }
  2074. X    }
  2075. X    abort ( "Undefined variable '%s' referenced" , name );
  2076. X    return ( 0.0 );
  2077. X}
  2078. X
  2079. X
  2080. X
  2081. Xis_var_ident ( name )
  2082. Xchar *name;
  2083. X{
  2084. X    int i;
  2085. X
  2086. X    for ( i = 0; i < num_dec; i++ ) {
  2087. X    if ( strcmp ( dec[i].name , name ) == 0 ) {
  2088. X        return ( 1 );
  2089. X    }
  2090. X    }
  2091. X    return ( 0 );
  2092. X}
  2093. X
  2094. X
  2095. SHAR_EOF
  2096. if test 1384 -ne "`wc -c < 'vardeclr.c'`"
  2097. then
  2098.     echo shar: error transmitting "'vardeclr.c'" '(should have been 1384 characters)'
  2099. fi
  2100. fi
  2101. if test -f 'lex.l'
  2102. then
  2103.     echo shar: will not over-write existing file "'lex.l'"
  2104. else
  2105. echo extracting "'lex.l'"
  2106. sed 's/^X//' >lex.l <<'SHAR_EOF'
  2107. X%{
  2108. X
  2109. X/*
  2110. X * Copyright (C) 1986   Alan Kent
  2111. X *
  2112. X * Permission is granted to freely distribute part or
  2113. X * all of this code as long as it is not for profit
  2114. X * and this message is retained in the code.
  2115. X *
  2116. X * No resposibility is taken for any damage or incorect
  2117. X * results this program generates.
  2118. X * 
  2119. X */
  2120. X
  2121. X
  2122. X/* Declaration section */
  2123. X
  2124. X#include <stdio.h>
  2125. X#include "graph.h"
  2126. X#include "y.tab.h"
  2127. X
  2128. Xextern int linenum;
  2129. Xextern char *    infilename;
  2130. X
  2131. Xextern char *    new ();
  2132. X
  2133. Xstatic struct {
  2134. X    char *word;
  2135. X    int token;
  2136. X} reserved[] = {
  2137. X    { "adjacent" , ADJACENT },
  2138. X    { "append" , APPEND },
  2139. X    { "as" , AS },
  2140. X    { "assume" , ASSUME },
  2141. X    { "at" , AT },
  2142. X    { "auto" , AUTO },
  2143. X    { "axis" , AXIS },
  2144. X    { "bottom" , BOTTOM },
  2145. X    { "by" , BY },
  2146. X    { "center" , CENTER },
  2147. X    { "centre" , CENTER },
  2148. X    { "circle" , CIRCLE },
  2149. X    { "cross" , CROSS },
  2150. X    { "cumulate" , CUMULATE },
  2151. X    { "date" , DATE },
  2152. X    { "dotdashed" , DOTDASHED },
  2153. X    { "dotted" , DOTTED },
  2154. X    { "format" , FORMAT },
  2155. X    { "frame" , FRAME },
  2156. X    { "from" , FROM },
  2157. X    { "generate" , GENERATE },
  2158. X    { "graph" , GRAPH },
  2159. X    { "grid" , GRID },
  2160. X    { "group" , GROUP },
  2161. X    { "include" , INCLUDE },
  2162. X    { "interval" , INTERVAL },
  2163. X    { "intervals" , INTERVAL },
  2164. X    { "into" , INTO },
  2165. X    { "join" , JOIN },
  2166. X    { "label" , LABEL },
  2167. X    { "left" , LEFT },
  2168. X    { "legend" , LEGEND },
  2169. X    { "line" , LINE },
  2170. X    { "linear" , LINEAR },
  2171. X    { "load" , LOAD },
  2172. X    { "logarithmic" , LOGRITHMIC },
  2173. X    { "logrithmic" , LOGRITHMIC },
  2174. X    { "longdashed" , LONGDASHED },
  2175. X    { "middle" , MIDDLE },
  2176. X    { "no" , NO },
  2177. X    { "outline" , OUTLINE },
  2178. X    { "parameter" , PARAMETER },
  2179. X    { "parms" , PARMS },
  2180. X    { "performing" , PERFORMING },
  2181. X    { "plot" , PLOT },
  2182. X    { "plus" , PLUS },
  2183. X    { "points" , POINTS },
  2184. X    { "power" , POWER },
  2185. X    { "print" , PRINT },
  2186. X    { "put" , PUT },
  2187. X    { "read" , READ },
  2188. X    { "right" , RIGHT },
  2189. X    { "save" , SAVE },
  2190. X    { "scale" , SCALE },
  2191. X    { "shell" , SHELL },
  2192. X    { "shortdashed" , SHORTDASHED },
  2193. X    { "size" , SIZE },
  2194. X    { "solid" , SOLID },
  2195. X    { "sort" , SORT },
  2196. X    { "square" , SQUARE },
  2197. X    { "str" , STR },
  2198. X    { "tick" , TICK },
  2199. X    { "to" , TO },
  2200. X    { "top" , TOP },
  2201. X    { "triangle" , TRIANGLE },
  2202. X    { "val" , VAL },
  2203. X    { "where" , WHERE },
  2204. X    { "with" , WITH },
  2205. X    { "xaxis" , XAXIS },
  2206. X    { "yaxis" , YAXIS },
  2207. X    { NULL , 0 }
  2208. X};
  2209. X
  2210. X%}
  2211. X
  2212. X%% /* Rules section */
  2213. X
  2214. X\<\=    { return ( LE ); }
  2215. X\>\=    { return ( GE ); }
  2216. X\<\>    { return ( NE ); }
  2217. X\!\=    { return ( NE ); }
  2218. X\=\=    { return ( EQ ); }
  2219. X\=    { return ( EQ ); }
  2220. X\>    { return ( GT ); }
  2221. X\<    { return ( LT ); }
  2222. X\"    { read_string (); return ( STRING ); }
  2223. X[a-zA-Z][a-zA-Z0-9_]*    {
  2224. X        int i;
  2225. X
  2226. X        for ( i = 0; reserved[i].word != NULL; i++ ) {
  2227. X        if ( strcmp ( yytext , reserved[i].word ) == 0 )
  2228. X            return ( reserved[i].token );
  2229. X        }
  2230. X        yylval.string = new ( strlen ( yytext ) + 1 );
  2231. X        strcpy ( yylval.string , yytext );
  2232. X        if ( is_tab_ident ( yytext ) )
  2233. X        return ( TAB_IDENT );
  2234. X        if ( is_var_ident ( yytext ) )
  2235. X        return ( VAR_IDENT );
  2236. X        if ( is_ftab_ident ( yytext ) )
  2237. X        return ( FTAB_IDENT );
  2238. X        if ( is_fvar_ident ( yytext ) )
  2239. X        return ( FVAR_IDENT );
  2240. X        return ( IDENT );
  2241. X    }
  2242. X[0-9.]+|[0-9.]+e[+-]?[0-9]+    {
  2243. X        double num;
  2244. X
  2245. X        scan_value ( yytext , &num );
  2246. X        yylval.number = num;
  2247. X        return ( NUMBER );
  2248. X    }
  2249. X\&\&    { return ( '&' ); /* synonym for & */ }
  2250. X\|\|    { return ( '|' ); /* synonym for | */ }
  2251. X[ \t]    ;
  2252. X\#.*\n    { linenum++; /* comment */ }
  2253. X\n    { linenum++; }
  2254. X.    { return ( yytext[0] ); }
  2255. X
  2256. X%% /* Subroutine section */
  2257. X
  2258. Xyyerror ( str )
  2259. Xchar *str;
  2260. X{
  2261. X    fprintf ( stderr , "%s: syntax error, line %d: %s\n" , infilename , linenum , str );
  2262. X}
  2263. X
  2264. X
  2265. Xread_string ()
  2266. X{
  2267. X    char buf[200];
  2268. X    char *p;
  2269. X    int c;
  2270. X
  2271. X    p = buf;
  2272. X    while ( c = yyinput () ) {
  2273. X    if ( c == '"' ) {
  2274. X        c = yyinput ();
  2275. X        if ( c == '"' )
  2276. X        *p++ = '"';
  2277. X        else {
  2278. X        yyunput ( c );
  2279. X        break;
  2280. X        }
  2281. X    }
  2282. X    else
  2283. X        *p++ = c;
  2284. X    }
  2285. X    *p = '\0';
  2286. X    yylval.string = new ( strlen ( buf ) + 1 );
  2287. X    strcpy ( yylval.string , buf );
  2288. X}
  2289. X
  2290. SHAR_EOF
  2291. if test 3973 -ne "`wc -c < 'lex.l'`"
  2292. then
  2293.     echo shar: error transmitting "'lex.l'" '(should have been 3973 characters)'
  2294. fi
  2295. fi
  2296. # end of shell archive
  2297. exit 0
  2298.